<?php

namespace app\api\controller;

use app\api\basic\BaseController;
use support\Request;
use app\park\logic\ParkIntroductionLogic;
use app\park\logic\ParkVideoLogic;
use app\api\basic\Auth;

use app\api\annotation\LoginRequired;

class ParkController extends BaseController {
    protected $userInfo;

    /**
     * 当前登陆管理员ID
     */
    protected $userId;

    /**
     * 当前登陆管理员账号
     */
    protected $userName;
    public function __construct()
    {   
        parent::__construct();
        $this->userId=request()->userId;
        $this->userName=request()->userName;
        $this->userInfo=request()->userInfo;
    }

     //园区展示
    #[LoginRequired(required: false)]
    public function parkDisplay(Request $request){
        $param = $request->more([
            ['lang_code','zh'], 
        ]);
        $ParkVideoLogic = new ParkVideoLogic();
        $ParkIntroductionLogic = new ParkIntroductionLogic();
        $ParkVideoTop=$ParkVideoLogic->search(['lang_code'=>$param['lang_code']])
        ->field('video_id,video_title,cover_image,video_path')
        ->where('is_display',1)
            ->order('sort_order desc')
            ->order('create_time desc')
        ->find();
        $ParkVideoTopId='';
        if($ParkVideoTop){
            $ParkVideoTopId=$ParkVideoTop->video_id;
            $ParkVideoTop=$ParkVideoTop->toArray();
        }
        $query=$ParkVideoLogic->search(['lang_code'=>$param['lang_code']]) ->field('video_id,video_title,cover_image,video_path');
        if($ParkVideoTopId){
            $query->where('video_id','<>',$ParkVideoTopId);
        }

        $ParkVideoLsit=$query->select();
        $parkIntroduction=$ParkIntroductionLogic->search(['lang_code'=>$param['lang_code']])
        ->value('introduction_text');
        return $this->success(['top'=>$ParkVideoTop,'list'=>$ParkVideoLsit,'introduction'=>$parkIntroduction]);
    }

    #[LoginRequired(required: false)]
    public function parkIntroduction(Request $request){
       
        $param = $request->more([
            ['lang_code','zh'],
            ['page',1],
            ['limit',10] 
        ]);
        $ParkVideoLogic = new ParkVideoLogic();
        $ParkVideoTop=$ParkVideoLogic->search(['lang_code'=>$param['lang_code']])
        ->field('video_id,video_title,cover_image,video_path')
        ->where('is_display',1)
        ->order('sort_order desc')
            ->order('create_time desc')
        ->find();
        $ParkVideoTopId='';
        if($ParkVideoTop){
            $ParkVideoTopId=$ParkVideoTop->video_id;
            $ParkVideoTop=$ParkVideoTop->toArray();
        }
        $query=$ParkVideoLogic->search(['lang_code'=>$param['lang_code']]) ->field('video_id,video_title,cover_image,video_path');
        if($ParkVideoTopId){
            $query->where('video_id','<>',$ParkVideoTopId);
        }

        $ParkVideoLsit=$query->paginate($param['limit']);
      
        return $this->success(['top'=>$ParkVideoTop,'list'=>$ParkVideoLsit->items(),'total'=>$ParkVideoLsit->total()]);
    }
}